<template>
	<view>
		<u-notice-bar v-if="project.id" :text="text1"></u-notice-bar>
		<view style="margin-top: 20rpx; padding: 15rpx; font-weight: 700">科技查新意向表</view>
		<view style="margin: 10rpx">
			<view class="text-class">
				单位名称
				<span style="color: red">*</span>
			</view>
			<view>
				<input class="input_style" :disabled="project.id" style="height: 60rpx" v-model="project.dwmc" />
			</view>
			<view class="text-class">
				联系人
				<span style="color: red">*</span>
			</view>
			<view>
				<input class="input_style" :disabled="project.id" style="height: 60rpx" v-model="project.lxr" />
			</view>
			<view class="text-class">
				联系电话
				<span style="color: red">*</span>
			</view>
			<view>
				<input class="input_style" :disabled="project.id" style="height: 60rpx" type="number" maxlength="11" v-model="project.lxdh" />
			</view>
			<view class="text-class">
				项目名称
				<span style="color: red">*</span>
			</view>
			<view>
				<input class="input_style" :disabled="project.id" style="height: 60rpx" v-model="project.xmmc" maxlength="20" placeholder="项目名称,不超过20字" />
			</view>
			<view class="text-class">
				项目内容
				<span style="color: red">*</span>
			</view>
			<view>
				<input class="input_style" :disabled="project.id" style="height: 260rpx; width: 90%; overflow-wrap: break-word" v-model="project.xmnr" />
			</view>
			<view class="text-class" v-if="!project.id">
				<button @click="submit()" class="btn_submit">提交</button>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
import env from '../../../utils/env';

import * as projectSearch from '@/api/projectSearch.js';

export default {
	components: {},
	data() {
		return {
			evaluationid: '',
			showMask: false,
			project: {
				xmmc: '',
				xmnr: '',
				lxr: '',
				dwmc: '',
				lxdh: ''
			},
			text1: '上传附件请去web端上传'
		};
	},
	onLoad(option) {
		if (option.id) {
			console.log(option.id);
			this.getData(option.id);
		}
	},
	methods: {
		getData(id) {
			projectSearch.getKJCXYXB(id).then((res) => {
				this.project = res.data;
			});
		},
		showToast(message){
			this.$refs.uToast.show({
				type: 'error',
				icon: false,
				message,
			});
		},
		submit() {
			if (this.project.xmmc == '') {
				this.showToast('项目名称不能为空！')
				return;
			} else if (this.project.xmnr == '') {
				this.showToast('项目内容不能为空！')
				return;
			} else if (this.project.lxr == '') {
				this.showToast('联系人不能为空！')
				return;
			} else if (this.project.dwmc == '') {
				this.showToast('单位名称不能为空！')
				return;
			} else if (this.project.lxdh == '') {
				this.showToast('联系电话不能为空！')
				return;
			} else if (this.project.lxdh.length < 11) {
				this.showToast('电话格式错误！')
				return;
			}
			uni.showModal({
				title: '提示',
				content: '确认该科技查新信息无误并提交吗？',
				showCancel: true,
				cancelText: '取消',
				confirmText: '提交',
				success: (res) => {
					if (res.confirm) {
						console.log('comfirm'); //点击确定之后执行的代码
						projectSearch.add(this.project).then((res) => {
							uni.showToast({
								icon: 'success',
								title: '提交成功！'
							});
							//加个延时
							uni.navigateBack();
						});
					} else {
						console.log('cancel'); //点击取消之后执行的代码
					}
				}
			});
		}
	}
};
</script>

<style>
.text-class {
	padding: 15rpx;
}

.input_style {
	margin: 20rpx;
	border-radius: 5%;
	border: 1px solid #d3d3d3;
	background-color: #fff;
	padding: 15rpx;
}

.btn_submit {
	background-color: #016fb8;
	color: white;
}
</style>
